package com.longshen.dubbo.api.base;

import java.io.Serializable;

import lombok.Getter;
import lombok.Setter;

/**
 * 
 * @ClassName: RestResult
 * @Description:
 * @author longshen
 * @date 2018年10月4日 上午10:11:59
 * 
 * @param <T>
 */
@Getter
@Setter
public class RestResult<T> implements Serializable {

	private static final long serialVersionUID = 6461151474191022757L;
	private String resultcode;
	private String message;
	private T data;

	private RestResult() {
	}
	
	
	

	public static <T> RestResult<T> newInstance() {
		return new RestResult<T>();
	}
	
	public static  RestResult fail(ErrorCode erroeCode) {
		RestResult rest=new RestResult();
		rest.setErrorCode(erroeCode);
		return rest;
	}

	
    public void setErrorCode(ErrorCode erroeCode) {
    	this.resultcode=erroeCode.getCode();
    	this.message=erroeCode.getDesc();
    }
	public static <T> RestResult<T>  success() {
		RestResult<T> result=	new RestResult<T>();
		result.setResultcode("000000");
		result.setMessage("success");
		return result;
		
	}
	public static <T> RestResult<T>  success(T t) {
		RestResult<T> result=	new RestResult<T>();
		result.setResultcode("000000");
		result.setMessage("success");
		result.setData(t);
		return result;
		
	}
}
